<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="会员名称、订单编号、买家手机号" clearable style="width:260px"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="dataForm.consigneeName" placeholder="收货人姓名" clearable style="width:130px"></el-input>
      </el-form-item>
      <el-form-item  label="" class="item-three">
					<el-select v-model="dataForm.priceTypes" placeholder="订单类型">
						<el-option label="兑换商城" value="1" ></el-option>
						<el-option label="福利商城" value="2" ></el-option>
					</el-select>
			</el-form-item>
      <el-form-item  label="" class="item-three">
					<el-select v-model="dataForm.userTypes" placeholder="用户类型">
						<el-option label="运营商" value="1" ></el-option>
            <el-option label="联盟店" value="2" ></el-option>
						<el-option label="vip会员" value="3" ></el-option>
            <el-option label="普通消费者" value="4" ></el-option>
						<el-option label="普通联盟店" value="5" ></el-option>
            <el-option label="高级联盟店" value="6" ></el-option>
						<el-option label="城市合伙人" value="7" ></el-option>
            <el-option label="联盟店城市合伙人" value="8" ></el-option>
					</el-select>
			</el-form-item>
      <el-form-item  label="" class="item-three">
					<el-select v-model="dataForm.orderTypes" placeholder="订单状态">
						<el-option label="已取消" value="0" ></el-option>
            <el-option label="未支付" value="10" ></el-option>
						<el-option label="待发货" value="20" ></el-option>
            <el-option label="已发货" value="30" ></el-option>
						<el-option label="已收货" value="40" ></el-option>
            <el-option label="已完成" value="50" ></el-option>
					</el-select>
			</el-form-item>
      <el-form-item label="上架时间" class="item-date">
            <el-date-picker
            v-model="dataForm.lastStart"
            type="datetime"
            value-format = "yyyy-MM-dd HH:mm:ss"
            placeholder="开始时间"
            :editable="false"
            :picker-options="startoptions"
            >
          </el-date-picker>
          <span class="span-to">~</span>
          		<el-date-picker
              v-model="dataForm.lastEnd"
              type="datetime"
              value-format = "yyyy-MM-dd HH:mm:ss"
              placeholder="截止时间"
              :editable="false"
              :picker-options="endoptions">
            </el-date-picker>
			</el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <!-- <el-button v-if="isAuth('orderform:shoppingorderform:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('orderform:shoppingorderform:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        label="ID">
      </el-table-column>
      <el-table-column
        prop="imgSrc"
        header-align="center"
        align="center"
        label="ID">
        <template slot-scope="scope">
          <img :src= "scope.row.imgSrc" style ="width:50%;hight:50%;"/>
        </template>
      </el-table-column>
      <el-table-column
        prop="USERNAME"
        header-align="center"
        align="center"
        label="会员账号">
      </el-table-column>
      <el-table-column
        prop="TRUENAME"
        header-align="center"
        align="center"
        label="会员名称">
      </el-table-column>
      <el-table-column
        prop="consignee"
        header-align="center"
        align="center"
        label="收货人">
      </el-table-column>
      <el-table-column
        prop="phone"
        header-align="center"
        align="center"
        label="手机号码">
      </el-table-column>
      <el-table-column
        prop="address"
        header-align="center"
        align="center"
        label="收货地址"
        width="160px"
        show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="orderId"
        header-align="center"
        align="center"
        label="订单编号"
        width="160px"
        show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="TOTALPRICE"
        header-align="center"
        align="center"
        label="订单总价">
      </el-table-column>
      <el-table-column
        prop="SHIPPRICE"
        header-align="center"
        align="center"
        label="运费">
      </el-table-column>
      <el-table-column
        prop="TOTALPRICE"
        header-align="center"
        align="center"
        label="订单总价">
      </el-table-column>
      <el-table-column
        prop="orderstatus"
        header-align="center"
        align="center"
        label="订单状态"
        :formatter="ORDERSTATUS">
      </el-table-column>
      <el-table-column
        prop="goodsname"
        header-align="center"
        align="center"
        label="商品名"
        width="160px"
        show-overflow-tooltip>
        <template slot-scope="scope">
          <a :href="scope.row.goodId" target="_blank" class="buttonText">{{scope.row.goodsname}}</a>
        </template>
      </el-table-column>
      <el-table-column
        prop="goodsserial"
        header-align="center"
        align="center"
        label="型号">
      </el-table-column>
      <el-table-column
        prop="pricetype"
        header-align="center"
        align="center"
        label="订单类型"
        :formatter="pricetype">
      </el-table-column>
      <el-table-column
        prop="specinfo"
        header-align="center"
        align="center"
        label="规格"
        width="160px"
        show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="count"
        header-align="center"
        align="center"
        label="数量">
      </el-table-column>
      <el-table-column
        prop="PAYTIME"
        header-align="center"
        align="center"
        label="支付时间"
        width="160px">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">查看</el-button>
          <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
  import AddOrUpdate from './shoppingorderform-add-or-update'
  export default {
    data () {
      return {
        dataForm: {
          keywords: '',
          consigneeName: '',
          priceTypes: '',
          userTypes: '',
          orderTypes: '',
          lastStart: '',
          lastEnd: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/orderform/shoppingorderform/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'consigneeName': this.dataForm.consigneeName,
            'priceTypes': this.dataForm.priceTypes,
            'userTypes': this.dataForm.userTypes,
            'orderTypes': this.dataForm.orderTypes,
            'lastStart': this.dataForm.lastStart,
            'lastEnd': this.dataForm.lastEnd
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/orderform/shoppingorderform/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },
      ORDERSTATUS (row, column) {
        if (row.orderstatus === 0) {
          return '已取消'
        } if (row.orderstatus === 10) {
          return '未支付'
        } if (row.orderstatus === 20) {
          return '待发货'
        } if (row.orderstatus === 30) {
          return '已发货'
        } if (row.orderstatus === 40) {
          return '已收货'
        } if (row.orderstatus === 50) {
          return '已完成'
        } if (row.orderstatus === 100) {
          return '已删除'
        }
      },
      pricetype (row, column) {
        if (row.pricetype === '1') {
          return '兑换商城'
        } if (row.pricetype === '2') {
          return '福利商城'
        }
      }
    }
  }
</script>
